package autosimmune.agents.pathogens.styles;

import java.awt.Color;
import java.awt.Image;
import java.awt.Paint;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import repast.simphony.visualization.visualization2D.style.Style2D;
import autosimmune.agents.pathogens.Bacteria;
import edu.umd.cs.piccolo.PNode;
import edu.umd.cs.piccolo.nodes.PImage;
import edu.umd.cs.piccolo.nodes.PText;

public class BacteriaStyle2D implements Style2D<Bacteria> {

	private Rectangle2D rect;
	
	private Image image;
	
	public BacteriaStyle2D(){
		rect = new Rectangle2D.Float(0, 0, 8, 8);
		String iconFile = "./icons/bacteria.png";
		BufferedImage im = null;
		File file = new File(iconFile);
		
		if (!file.exists()){
			System.err.println("Arquivo " + iconFile + " não encontrado.");
		}
		
		try {
			im = ImageIO.read(file);
			PImage pimage = new PImage(im);
			AffineTransform trans = new AffineTransform();
			trans.setToScale(1, -1);
			pimage.transformBy(trans);
			image = pimage.toImage();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public Rectangle2D getBounds(Bacteria object) {
		return rect;
	}

	@Override
	public PText getLabel(Bacteria object) {
		return null;
	}

	@Override
	public PNode getPNode(Bacteria object, PNode node) {
		if (image == null){
			System.err.println("Erro ao carregar imagem da Bacteria.");
			return null;
		}
		PImage pimage = new PImage(image);
		pimage.setBounds(new Rectangle2D.Float(0, 0, 10, 10));
		return pimage;
	}

	@Override
	public Paint getPaint(Bacteria object) {
		return Color.WHITE;
	}

	@Override
	public double getRotation(Bacteria object) {
		return 0;
	}

	@Override
	public Stroke getStroke(Bacteria object) {
		return null;
	}

	@Override
	public Paint getStrokePaint(Bacteria object) {
		return null;
	}

	@Override
	public boolean isScaled(Bacteria object) {
		return true;
	}


}
